﻿using Dispatcher.Core.Wechat;
using Dispatcher.Core.Wechat.Models;
using Dispatcher.Data.Entities.MySql;
using MiniFox.Components;
using MiniFox.Data.EntityFramework;
using MiniFox.Utility;

namespace Dispatcher.Data
{
    /// <summary>
    /// 
    /// </summary>
    [AutoResolve]
    public class WechatProvider : EntityDataProvider<DispatcherContext>, IWechatProvider
    {

        public void SaveMessageResult(WechatSendRequest request, WechatSendResponse response)
        {
            var dataItem = new WechatSent
            {
                MessageId = response.MessageId,
                AccountName = request == null ? string.Empty : request.AccountName,
                TemplateName = request.TemplateName,
                Data = request == null ? string.Empty : request.Data.ToJsonString(),
                Receiver = request == null ? string.Empty : request.Receiver.ToJsonString(),
                Title = request == null ? string.Empty : request.Title,
                Url = request == null ? string.Empty : request.Url,
                PictureUrl = request.PictureUrl,
                Response = response.OrignalResponse,
                Body = request == null ? string.Empty : request.Body,
                SendTime = DateTime.Now
            };
            this.Insert(dataItem);
        }
    }
}
